package com.plugin.test

import org.gradle.api.Plugin
import org.gradle.api.Project

class KtGreetingPlugin : Plugin<Project> {
    override fun apply(project: Project) {
        project.logger.error("KtGreetingPlugin say hello")
        val extension = project.extensions.create("greeting", KtGreetingPluginExtension::class.java)
        project.task("hello").apply {
            doFirst {
                project.logger.error("hello do first")
            }
            project.logger.error("task: hello")
            doLast {
                project.logger.error("${extension.message} ${extension.javaEnable}")
            }
        }
        getFeature(project)
    }

    private fun getFeature(project: Project) {
        project.afterEvaluate {
            val config = project.extensions.findByType(KtGreetingPluginExtension::class.java) ?: return@afterEvaluate
            println("config: ${config.message} ${config.javaEnable}")
        }
    }
}


open class KtGreetingPluginExtension {
    var message: String = ""
    var javaEnable: Boolean = false
}